require 'rubygems'
require 'savon'

class AddressInfo

  def initialize

    @client = Savon::Client.new do
      wsdl.document = "http://padovan.org:3000/address_services/wsdl"
#      wsdl.element_form_default = :unqualified
    end

  end

  def find_by_zip(zip)
    
    r = @client.request :cep_address do
      soap.body = {
        :cep => zip
      }
    end
    h = r.to_hash
    a = h[:cep_address_response][:return][:address]
    Address.new(:street => a[:logradouro], :district => a[:bairro], :city => a[:localidade], :state => a[:uf], :zip => zip)
  end
  
end
